package com.nebrija.riif.model;

import java.util.Set;

public class State extends RIIFProperties {

	public static final String DURATION = "duration";
	public static final String NEXT = "next";
	
	private StateType localType = StateType.NONE;

	public State(String name) {
		super(name);
	}
	
	public State(String name, StateType type) {
		super(name);
		this.localType=type;
	}
	
	public void setStateType(StateType type){
		this.localType=type;
	}
	
	public StateType getStateType(){
		return this.localType;
	}
	
	@Override
	public String toString() {
		
		StringBuffer str = new StringBuffer (name);
		str.append("\n");
		str.append("TYPE: ").append(localType);
		str.append("\n");
		Set<String> keys = props.keySet();
		for (String key: keys){
			str.append("\t->").append(key)
				.append(":").append(props.get(key)).append("\n");
		}
		

		return str.toString();
	}

	public String getNextStateName(){
		return (String)getProperty(NEXT);
	}
	
	public ValueTimeUnit getDuration(){
		Object duration = getProperty(DURATION+CALCULATED_SUFFIX);
		if(duration!=null){
			return (duration instanceof String)?ValueTimeUnit.stringToVTU((String)duration):(ValueTimeUnit)duration;
		}
		return null;
	}

	@Override
	public void resolve(RIIFElement container) {
		// TODO Auto-generated method stub
		super.resolve(container);
	}

}
